//
//  ArrayDataSource.m
//  27-ArrayDataSource
//
//  Created by Snow on 16/8/19.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ArrayDataSource.h"

@interface ArrayDataSource ()
//声明初始化参数对应的属性
@property (nonatomic, copy) NSString *reuse;
@property (nonatomic, copy) NSArray *dataSource;
@property (nonatomic, copy) configCell configCell;
@end
@implementation ArrayDataSource
- (instancetype)initWithtableViewCellReuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(configCell)configCell
{
    self = [super init];
    if (self) {
        //属性赋值
        _reuse = reuse;
        _dataSource = array;
        _configCell = configCell;
    }
    return self;
}
+ (instancetype)arrayDataSourceinitWithtableViewCellReuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(configCell)configCell
{
    return [[self alloc]initWithtableViewCellReuse:reuse arrayDataSource:array configCell:configCell];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_reuse];
    cell.textLabel.text = [_dataSource objectAtIndex:indexPath.row];
    id model = _dataSource[indexPath.row];
    //根据数据源和cell调用block
    self.configCell(cell, model);
    return cell;
}
@end
